package com.aofeng.hybridwork.android.task;

import android.app.ProgressDialog;
import android.os.AsyncTask;

import com.aofeng.hybrid.activity.HybridActivity;
import com.aofeng.hybrid.service.EntityService;
import com.aofeng.hybrid.service.SqlService;

import org.json.JSONObject;

/**
 * 下载安检计划异步任务
 * Created by LGY on 2016-08-25.
 */
public class deleteAsyncTask extends AsyncTask<String, String, Boolean> {
    HybridActivity hybridActivity;
    //计划在客户端的序号，回调用
    String index;


    public deleteAsyncTask(HybridActivity hybridActivity) {
        this.hybridActivity = hybridActivity;
    }
    @Override
    /**
     * params:
     * 下载的url
     */
    protected Boolean doInBackground(String... params) {
        try {
            index = "1";

            //fuck for the illusion
            //删除hand plan表内相同册号的数据
            publishProgress(new String[]{ 35 + "", "保存出错数据......"});
            SqlService ss = new SqlService(hybridActivity);
            ss.run("delete from t_check_plan ");
            ss.run("delete from t_aboutuser");
            ss.run("delete from t_equipmentinspection ");
            ss.run("delete from t_hinvestigation ");
            publishProgress(new String[]{ 100 + "", "保存完成。"});
            return true;
        } catch(Exception e) {
            return false;
        }
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        hybridActivity.createProgressDialog(ProgressDialog.STYLE_SPINNER);
    }

    @Override
    protected void onPostExecute(Boolean flag) {
        super.onPostExecute(flag);
        hybridActivity.closeProgress();
        hybridActivity.mWebView.loadUrl("javascript:HostApp.__callback__(" + flag +");");
    }

    @Override
    protected void onProgressUpdate(String... values) {
        super.onProgressUpdate(values);
        int progress = Integer.parseInt(values[0]);
        hybridActivity.setProgress(progress, values[1]);
    }
}